package com.hmall.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;

import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author Acer
 */
//@Component
@Order(0)
@Slf4j
public class MyGlobalFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain){

//        记录日志
        log.info("过滤器MyGlobalFilter 执行");
//        拦截请求
        ServerHttpResponse response = exchange.getResponse();
        response.setRawStatusCode(HttpStatus.SC_UNAUTHORIZED);
        //表示已完成，返回
        return response.setComplete();

//        放行请求
//        return chain.filter(exchange);
    }
}
